package com.jianghu;

import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
public class Article extends Activity {
	private WebView web;
	private PopupWindow pop;
	private LinearLayout articleLayout;
	Timer timer;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.article);
		Init();
		articleLayout.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				pop.showAtLocation(web, Gravity.CENTER, 0, 2000);
				timer=new Timer();
				timer.schedule(new TimerTask() {	
					@Override
					public void run() {
						pop.dismiss();
					}
				},10000);
			}
		});
	}
	

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (timer!=null) {
				timer.cancel();
			}
			if (pop != null && pop.isShowing()) {
				pop.dismiss();
			}
		}
		return super.onKeyDown(keyCode, event);
	}


	private void Init() {
		articleLayout=(LinearLayout)findViewById(R.id.articlelayout);
		web=(WebView)findViewById(R.id.webview);
		View view=getLayoutInflater().inflate(R.layout.popwindow, null);
		pop=new PopupWindow(view,LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
	}
}
